package com.accp.action;

import java.util.List;

import javax.annotation.Resource;


import com.accp.biz.RoleBiz;
import com.accp.biz.UserBiz;
import com.accp.entity.Department;
import com.accp.entity.Role;
import com.accp.entity.User;

public class UserAction {
	
	@Resource
	private UserBiz userBiz;
	@Resource
	private RoleBiz roleBiz;

	private List<User>  users;
	private User user;
	private int uid;
	private List<Role> roles;
	private List<Department> departs;
	private int flag;
	
	
	
	
	

	/*
	 * 查询所有用户
	 */
	public String queryUsers(){
		users=userBiz.queryUsers(user);
		return showRBlist();
	}
	/*
	 * 公共方法，获取角色，部门列表
	 */
	public String showRBlist(){
		//获取角色列表
		roles=roleBiz.queryRoles();
		//获取部门列表
		departs=userBiz.queryDeparts();
		if(users!=null||user!=null){
			return "success";
		}
		return "error";
	}
/*
 * 用户登录功能
 */
	public String loginUser(){
		user=userBiz.queryUser(user);
		if(user!=null){
			return "success";
		}
		return "error";
	}
	/*
	 * 添加用户
	 */
	public String addUser(){
		if(userBiz.addUser(user)){
			flag=1;
			return "success";
		}
		return "error";
	}
	/*
	 * 查询单个用户用于修改
	 */
	public String queryUser(){
		user=userBiz.queryUser(new User(uid));
		return showRBlist();
	}
	/*
	 * 修改用户
	 */
	public String updateUser(){
		if(userBiz.updateUser(user)){
			flag=2;
			return "success";
		}
		return "error";
	}
	/*
	 * 删除用户
	 */
	public String delUser(){
		if(userBiz.delUser(user)){
			flag=3;
			return "success";
		}
		return "error";
	}

	
	public String addRole(){
		return "success";
	}
	public String updateRole(){
		return "success";
	}
	
	
	
	
	public int getUid() {
		return uid;
	}
	public void setUid(int uid) {
		this.uid = uid;
	}
	public int getFlag() {
		return flag;
	}
	public void setFlag(int flag) {
		this.flag = flag;
	}
	public List<Department> getDeparts() {
		return departs;
	}
	public void setDeparts(List<Department> departs) {
		this.departs = departs;
	}
	public List<Role> getRoles() {
		return roles;
	}
	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}
	public List<User> getUsers() {
		return users;
	}
	public void setUsers(List<User> users) {
		this.users = users;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User u) {
		this.user = u;
	}
	
	
}
